package top.kaoshanji.p1ch02b;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.p1ch02b.exception.GreetException;
import top.kaoshanji.p1ch02b.impl.GreetV1Impl;

/**
 * 代码清单 p1ch02b-07：使用案例(2.3.2节)
 * @see GreetFactory
 * author kaoshanji
 * ^_^
 * create time 2024/12/23 21:06
 */
public class GreetUsage {

    private static final Logger logger = LogManager.getLogger(GreetUsage.class);

    public static void main(String[] args) throws GreetException {
        logger.info("...代码清单 p1ch02b-07：使用案例(2.3.2节)...");

        // 运行的结果显示的是都是 GreetV1

        GreetV1 greetV1 = new GreetV1Impl();
        System.out.println(greetV1.greet("Alex1", "男"));

        // adaptGreet 方法接收的是 GreetV1 的一个实现类
        // 然后将这个实现类代理给了 GreetV2
        GreetV2 greetV2 = GreetFactory.adaptGreet(greetV1); // 关键点


        System.out.println(greetV2.greet("Alex2"));

    }

}
